package com.wpam.scrabble.mobile.messages;

import java.util.Map;

import com.wpam.scrabble.mobile.activities.GameSettingsActivity;
import com.wpam.scrabble.mobile.GameLogic;
import com.wpam.scrabble.mobile.ScoreBoard;
import com.wpam.scrabble.mobile.GameData;
import com.wpam.scrabble.mobile.ui.GameBoard;

public class InfoMessage extends Message {

	private static final long serialVersionUID = 1L;

	private String serverType_;
	private boolean recruiting_;
	private int turnTime_;
	private boolean wordCheck_;
	private boolean hints_;
	private int hintLetters_;
	private boolean hackEnabled_;

	private GameData gameData_;
	
	public InfoMessage(Map<String, ?> map) {

		super(Message.INFO);
		this.gameData_ = null;
		init(map);
	}

	public InfoMessage() {
		
		super(Message.INFO);
		this.gameData_ = null;
		this.serverType_ = null;
		this.turnTime_ = 0;
		this.wordCheck_ = false;
		this.hints_ = false;
		this.hintLetters_ = 0;
		this.hackEnabled_ = false;
		this.recruiting_ = false;
	}
	
	public InfoMessage(Map<String, ?> map, GameBoard gameBoard, ScoreBoard scoreBoard, String receiverName) {
		
		super(Message.INFO);
		this.gameData_ = new GameData(gameBoard, scoreBoard, GameLogic.getInstance().getLettersOfPlayer(receiverName));
		init(map);
	}
	
	private void init(Map<String, ?> map) {

		this.recruiting_ = true;
		serverType_ = (String)map.get(GameSettingsActivity.SERVER_TYPE);
		turnTime_ = Integer.parseInt((String) map.get(GameSettingsActivity.TURN_TIME));
		try {
			wordCheck_ = (Boolean)map.get(GameSettingsActivity.WORD_CHECK);
		}
		catch (NullPointerException e) {
			wordCheck_ = false;
		}
	}
	
	public String getServerType() {
		return serverType_;
	}
	
	public boolean isRecruiting() {
		return recruiting_;
	}
	
	public int getTurnTime() {
		return turnTime_;
	}
	
	public boolean isWordCheck() {
		return wordCheck_;
	}
	
	public boolean isHintEnabled() {
		return hints_;
	}
	
	public int getHintLetters() {
		return hintLetters_;
	}
	
	public boolean isHackEnabled() {
		return hackEnabled_;
	}
	
	public GameData getGameData() {
		return gameData_;
	}
}
